package com.itqf.Controller;

import com.github.pagehelper.PageInfo;
import com.itqf.Enum.CodeEnum;
import com.itqf.Service.Topic.TopicService;
import com.itqf.Util.DTO.ResultDTO;
import com.itqf.Util.myPageInfo;
import com.itqf.entity.Topic;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


@Controller
@RequestMapping("/huileme/a/m/HotsearchController")
public class HotsearchController {
    @Resource
    private TopicService topicService;


    @RequestMapping(value = "/hotsearch",method = RequestMethod.POST)
    @ResponseBody
    /**
        * @Description:
        * @Param: [pageindex, searchname, request]
        * @return: com.github.pagehelper.PageInfo<com.itqf.entity.Topic>
        * @Author: 赵渊
        * @Date: 20:22
        */ //热门搜索的搜索内容
    public ResultDTO<PageInfo> gettopics(@RequestParam(defaultValue = "1") int pageindex, String searchname, HttpServletRequest request)
    {
        PageInfo<Topic> findbysearchname = topicService.findbysearchname(pageindex, myPageInfo.PAGESIZE, searchname);

        ResultDTO resultDTO=new ResultDTO();

        if (!findbysearchname.getList().isEmpty())
        {
              resultDTO.setData(findbysearchname);
              resultDTO.setMessage(CodeEnum.selectsuccess.getMsg());
              resultDTO.setCode(CodeEnum.selectsuccess.getCode());
        }else
        {
            resultDTO.setData(findbysearchname);
            resultDTO.setMessage(CodeEnum.selecterror.getMsg());
            resultDTO.setCode(CodeEnum.selecterror.getCode());
        }

        return resultDTO;
    }
   /* //热门搜索回显数据
    @RequestMapping(value = "/hotsearchdata",method = RequestMethod.POST)
    @ResponseBody
    public Object gethostsearchdata(HttpServletRequest request)
    {
        HttpSession session = request.getSession();
        Map map=(Map)session.getAttribute("map");
        Collection values = map.values();

         return values;
    }*/
}
